home *** CD-ROM | disk | FTP | other *** search
- //____________________________________________________________
- // SoundCommands.c
- //
- // Copyright © Dan Parks Sydow, 1995
- // From the book:
- // "Graphics and Sound Programming Techniques for the Mac",
- // M&T Books, 1995
- //
- // The "Graphics and Sound Programming for the Mac" book shows the call to SndPlay()
- // with a different second parameter than the one used in this code. The book shows the
- // SndPlay() call as expected by the version of the Sound.h universal header file used
- // by Metrowerks at the time of this writing. Symantec uses a different version of
- // Sound.h. If Symantec updates the Apple Universal Header files, you may get a compilation
- // error. If you do, it will concern the call to SndPlay() in the PlaySoundResourceSynch() function.
- // Here is the change you'll need to make. Change
- // FROM:
- //
- // theError = SndPlay( theChannel, theHandle, false );
- //
- // TO:
- //
- // theError = SndPlay( theChannel, (SndListHandle)theHandle, false );
-
-
-
- //____________________________________________________________
-
- #include <Sound.h>
-
-
- //____________________________________________________________
-
- void InitializeToolbox( void );
- SndChannelPtr OpenOneSynchSoundChannel( void );
- OSErr DisposeOneSoundChannel( SndChannelPtr );
- OSErr PlaySoundResourceSynch( SndChannelPtr, short );
- OSErr SetSoundAmplitude( SndChannelPtr, short );
-
- //____________________________________________________________
-
- #define rPoliceSiren 9000
-
-
- //____________________________________________________________
-
- void main( void )
- {
- NumVersion theSndMgrVers;
- short theResID;
- OSErr theError;
- SndChannelPtr theChannel;
- short theAmplitude;
-
- InitializeToolbox();
-
- theSndMgrVers = SndSoundManagerVersion();
- if ( theSndMgrVers.majorRev < 3 )
- ExitToShell();
-
- theChannel = OpenOneSynchSoundChannel();
- if ( theChannel == nil )
- ExitToShell();
-
- theAmplitude = 50;
- theError = SetSoundAmplitude( theChannel, theAmplitude );
- if ( theError != noErr )
- ExitToShell();
-
- theResID = rPoliceSiren;
- theError = PlaySoundResourceSynch( theChannel, theResID );
- if ( theError != noErr )
- ExitToShell();
-
- theError = DisposeOneSoundChannel( theChannel );
- if ( theError != noErr )
- ExitToShell();
- }
-
-
- //____________________________________________________________
-
- OSErr SetSoundAmplitude( SndChannelPtr theChannel, short theAmp )
- {
- SndCommand theCommand;
- OSErr theError;
-
- theCommand.cmd = ampCmd;
- theCommand.param1 = theAmp;
- theCommand.param2 = 0;
-
- theError = SndDoCommand( theChannel, &theCommand, false );
-
- return ( theError );
- }
-
-
- //____________________________________________________________
-
- SndChannelPtr OpenOneSynchSoundChannel( void )
- {
- SndChannelPtr theChannel;
- OSErr theError;
-
- theChannel = nil;
- theError = SndNewChannel( &theChannel, 0, 0, nil );
-
- if ( theError != noErr )
- {
- DisposePtr( (Ptr)theChannel );
- theChannel = nil;
- }
-
- return ( theChannel );
- }
-
-
- //____________________________________________________________
-
- OSErr DisposeOneSoundChannel( SndChannelPtr theChannel )
- {
- OSErr theError;
-
- theError = SndDisposeChannel( theChannel, true );
- DisposePtr( (Ptr)theChannel );
-
- return ( theError );
- }
-
-
- //____________________________________________________________
-
- OSErr PlaySoundResourceSynch( SndChannelPtr theChannel, short theResID )
- {
- Handle theHandle;
- OSErr theError;
-
- theHandle = GetResource( 'snd ', theResID );
-
- if ( theHandle == nil )
- {
- return ( resProblem );
- }
- else
- {
- HLock( theHandle );
- theError = SndPlay( theChannel, theHandle, false );
- HUnlock( theHandle );
-
- ReleaseResource( theHandle );
-
- return ( theError );
- }
- }
-
-
- //____________________________________________________________
-
- void InitializeToolbox( void )
- {
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( 0L );
- FlushEvents( everyEvent, 0 );
- InitCursor();
- }
-